<?php

/**
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
//App::uses('View', 'View');

/**
 * A view class that is used for PHP eval.
 *

 * @package       Cake.View
 * @since         CakePHP(tm) v 1.0.0
 */
class PhpView extends View {

    /**
     * Constructor
     *
     * @param Controller $controller
     */
    public function __construct(Controller $controller = null) {
        parent::__construct($controller);
    }

    /**
     * Sandbox method to evaluate a template / view script in.
     *
     * @param string $viewFn Filename of the view
     * @param array $dataForView Data to include in rendered view.
     *    If empty the current View::$viewVars will be used.
     * @return string Rendered output
     */
    protected function _evaluate($viewFile, $dataForView) {
        preg_match_all('/{{!(.*?)!}}/', $dataForView['paginas']['Pagina']['descricao'], $matches);
        if (count($matches) > 0) {
            foreach ($matches[0] as $key => $value) {
                $dataForView = str_replace($value, eval('return ' . $matches[1][$key]), $dataForView);
            }
        }
        return parent::_evaluate($viewFile, $dataForView);
    }

}
